#ifndef IEDITOR_H
#define IEDITOR_H

#include "ieditoritem.h"

#include <QtCore/QSharedPointer>
#include <QtGui/QBitmap>
#include <QtGui/QPixmap>

QT_BEGIN_NAMESPACE
class QAction;
class QWidget;
class QMimeData;
QT_END_NAMESPACE

namespace core
{
class EditorManager;
class IDocument;

class GalleryItemThumbnail
{
public:
    GalleryItemThumbnail() : GalleryRole(), DragAndDropRole() {}
    GalleryItemThumbnail(const QPixmap& galRole,
        const QPixmap& dragRole = QPixmap(),
        const QBitmap& conRole = QBitmap()) : GalleryRole(galRole),
            DragAndDropRole(dragRole), ConnectRole(conRole) {}

public:
    QPixmap GalleryRole;
    QPixmap DragAndDropRole;
    QBitmap ConnectRole;
};

class GalleryItem
{
public:
    GalleryItem() : Thumbnail(), Label(), Action(0), DragData(0),
        ConnectData(0) {}

    GalleryItem(const GalleryItem& other) : Thumbnail(other.Thumbnail),
        Label(other.Label), Action(other.Action), DragData(other.DragData)
    {
        ConnectData = other.ConnectData != 0 ? new ConnectionData(other.ConnectData->ConnectionId,
            other.ConnectData->Connector, other.ConnectData->From,
            other.ConnectData->To) : 0;
    }

    ~GalleryItem()
    {
        delete ConnectData;
    }

    GalleryItem& operator= (const GalleryItem& other)
    {
        if (this != &other)
        {
            Thumbnail = other.Thumbnail;
            Label = other.Label;
            Action = other.Action;
            DragData = other.DragData;
            ConnectData = other.ConnectData != 0 ? new ConnectionData(
                other.ConnectData->ConnectionId,
                other.ConnectData->Connector,
                other.ConnectData->From,
                other.ConnectData->To) : 0;
        }

        return *this;
    }

public:
    GalleryItemThumbnail Thumbnail;
    QString Label;
    QAction* Action;
    QMimeData* DragData;
    ConnectionData* ConnectData;
};

class IEditor
{
public:
    enum State
    {
        SelectMove,
        Transform,
        // non-displayable (associated actions are hidden to user) states
        Edit,
        Connect
    };

public:
    virtual void open(const QSharedPointer<IDocument>& document) = 0;
    virtual void close(const QSharedPointer<IDocument>& document) = 0;

    virtual QSharedPointer<IDocument> document() const = 0;
    virtual QWidget* widget() const = 0;

    virtual QStringList galleryGroups() const = 0;
    virtual QList<GalleryItem> galleryItems(const QString& group) const = 0;

    virtual void registerFocusListener(QObject* object) = 0;
    virtual void unregisterFocusListener(QObject* object) = 0;

    virtual ~IEditor() {}

protected:
    virtual IEditor* copy() const = 0;

private:
    friend class EditorManager;
};

} // namespace core

#endif
